package com.smec.remes.smecManager.SmecRetrofit.Interceptor;



import android.content.SharedPreferences;
import android.util.Log;

import com.smec.moblie.SMECApplication;
import com.smec.moblie.activity.LoginActivity;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * Created by xupeizuo on 2017/7/27.
 */

public class TokenInterceptor implements Interceptor {
    @Override
    public Response intercept(Chain chain) throws IOException {

        SharedPreferences mySharedPreferences=
                SMECApplication.getContext().getSharedPreferences("ElevatorSharedPreferences", LoginActivity.MODE_PRIVATE);

        Request request = chain.request().newBuilder()
                .addHeader("DF_KEY",mySharedPreferences!=null ? mySharedPreferences.getString("TOKEN",""):"")
                .build();
        Response response = null ;
        try {
            response = chain.proceed(request);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return response;
    }
}
